// pages/get-money-start/index.js
const handler = require("../../utils/function.js");
const { $Message } = require('../../dist/base/index');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    money:"",
    is_get_money:false,
    userData:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.initData();
  },
// 获取提现金额
  get_money:function(e){
    var test_money = handler.regTest(e.detail.value,"请输入提现金额");
    test_money&&this.setData({ money:e.detail.value});
  },
  // 提现
  get_mongey_handler:function(){
    var test_money = handler.regTest(this.data.money, "请输入提现金额");
    if (test_money){
       if(this.data.money < 1){
         $Message({ content: "提现最低1元起", type: "error" })
       }else{
         var para ={
           openid:wx.getStorageSync('user_info').openid,
           amount:this.data.money,
           desc:'余额提现',
           id:wx.getStorageSync('user_info').id
         };
         var that = this;
         handler.requestData("withdrawal", para, function (res) {
           if (res.success == true) {
              $Message({ content: "提现成功", type: "success" })
              handler.intoPageHandler("../get-money/index");
           } else {
             $Message({ content: res.message, type: "error" })
           }
         });
       }
    }else{
      $Message({ content: "提现失败，请重新输入金额", type: "error" })
    }
    
  },
  initData: function () {
    var para = {
       openid:wx.getStorageSync('user_info').openid
    };
    debugger
    var that = this;
    handler.requestData("balance", para, function (res) {
      if (res.success == true) {
        that.setData({
          userData:res.data
        })
      } else {
        wx.showToast({
          title: res.message,
          icon: 'loading'
        })
      }
    });
  },
  allMoney:function(){
    this.initData();
    this.setData({
      money:this.data.userData.money
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})